require(["common", "jQuery", "coAjax", "queryString", "href", "hash_routie"], function(jSouper, $, coAjax, QueryString, href, hash_routie) {
	var _num = 10;
	var _page;
	queryString = new QueryString(location.hash);
	hash_routie.on("goodsmanage", function() {
		_page = 0;
		App.set("title", "商品管理");
		if (queryString.get("cid") == 1) {
			alert("success", "修改成功");
		};
		_init_goods_data();
	})

	function _load_goods_page(num, page) {
		App.model.toggle('isloading');
		coAjax.get(appConfig.goods.list_with_page_info, {
			bus_id: busInfo._id,
			num: num,
			page: page
		}, function(result) {
			var info = result.result;
			if (!info.goods.length) {
				App.model.toggle("ismore");
			};
			console.log("bus.goods", info.goods);
			App.concat("goods", info.goods);
			App.model.toggle("isloading");
		});
	};

	function _init_goods_data() {
		_load_goods_page(_num, _page);
	};

	//删除商品
	App.set("$Event.remove_goods", function(e, vm) {
		console.log("hehe")
		myConfirm("确定删除“" + vm.get("goods_name") + "”", function(result) {
			coAjax["delete"](appConfig.bus.remove_goods, {
				goods_id: vm.get("_id"),
				bus_id: busInfo._id
			}, function(result) {
				App.set("goods", result.result);
			});
		}, function() {
			console.log("取消删除");
		});
	});
	//修改商品
	App.set("$Event.update_goods", function(e, vm) {
		App.set("$Cache.goods_to_update", vm.get());
		location.hash = "default/goodsupdate?id=" + vm.get("_id");
	});
	App.set("$Event.to_down", function(e, vm) {
		_page += 1;
		_load_goods_page(_num, _page);
	});
});